package com.newtouch.bxzs.business.message.controller;

import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.message.model.AnnouncementAddVO;
import com.newtouch.bxzs.business.message.model.AnnouncementBO;
import com.newtouch.bxzs.business.message.model.AnnouncementDetailBO;
import com.newtouch.bxzs.business.message.model.AnnouncementVO;
import com.newtouch.bxzs.business.message.service.AnnouncementService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公告管理的controller类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/23</td>
 * <td>liman</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author liman
 * @version 1.0.0
 * @since 1.0.0
 */

@Api(tags = "公告管理")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/announcementController")
public class AnnouncementController {
    @Resource
    private AnnouncementService announcementService;

    /**
     * 静态变量：日志
     */
    private static final Log logger = LogFactory.getLog(AnnouncementController.class);

    @ApiOperation("获取公告列表")
    @PostMapping("/getAnnouncementList")
    @MyLog(systemFunctionName = "公告管理", systemFunctionUrl = "/announcementController/getAnnouncementList", userOperationType = 4, userOperationSummary = "获取公告列表")
    public BaseResponse<AnnouncementBO> getAnnouncementList(@RequestBody AnnouncementVO announcementVO) {
        logger.info("获取公告列表");
        return RespGenerator.returnOK(announcementService.getAnnouncementList(announcementVO));
    }

    @ApiOperation("获取公告详细信息")
    @ApiImplicitParam(name = "announcementId", value = "公告id", dataType = "String", required = true)
    @GetMapping("/getAnnouncementDetail")
    @MyLog(systemFunctionName = "公告管理", systemFunctionUrl = "/announcementController/getAnnouncementDetail", userOperationType = 4, userOperationSummary = "获取公告详细信息")
    public BaseResponse<AnnouncementDetailBO> getAnnouncementDetail(@RequestParam(value = "announcementId") String announcementId) {
        logger.info("获取公告详情");
        return RespGenerator.returnOK(announcementService.getAnnouncementDetail(announcementId));
    }

    @ApiOperation("批量逻辑删除公告")
    @PostMapping("/deleteAnnouncement")
    @MyLog(systemFunctionName = "公告管理", systemFunctionUrl = "/announcementController/deleteAnnouncement", userOperationType = 3, userOperationSummary = "批量逻辑删除公告")
    public BaseResponse<String> deleteAnnouncement(@RequestBody @ApiParam(value = "公告id的集合", required = true) List<String> announcementIds) {
        logger.info("批量逻辑删除公告");
        return RespGenerator.returnOK(announcementService.deleteAnnouncement(announcementIds));
    }


    @ApiOperation("新增、修改或暂存公告")
    @PostMapping("/modifyAnnouncement")
    @MyLog(systemFunctionName = "公告管理", systemFunctionUrl = "/announcementController/modifyAnnouncement", userOperationType = 5, userOperationSummary = "新增、修改或暂存公告")
    public BaseResponse<String> modifyAnnouncement(@RequestBody AnnouncementAddVO announcementVO) {
        logger.info("新增、修改或暂存公告");
        return RespGenerator.returnOK(announcementService.modifyAnnouncement(announcementVO));
    }

    @ApiOperation("发布或者撤销公告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "announcementId", value = "公告ID", dataType = "String", required = true),
            @ApiImplicitParam(name = "announcementStatus", value = "公告发布状态,未发布1；已发布2；已结束3；已取消4；已撤销5", dataType = "String", required = true)
    })
    @GetMapping("/changeAnnouncementStatus")
    @MyLog(systemFunctionName = "公告管理", systemFunctionUrl = "/announcementController/changeAnnouncementStatus", userOperationType = 2, userOperationSummary = "发布或者撤销公告")
    public BaseResponse<String> changeAnnouncementStatus(
            @RequestParam(value = "announcementId") String announcementId,
            @RequestParam(value = "announcementStatus") String announcementStatus
    ) {
        logger.info("发布或者撤销公告");
        return RespGenerator.returnOK(announcementService.changeAnnouncementStatus(announcementId, announcementStatus));
    }
}
